<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Asset_main_cat extends CI_Controller {


	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');
		$this->load->library('PHPexcel');
	}

	public function index(){
	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'));
	  $this->load->view('layouts/footer');
	 }

	 public function add_form(){
		$this->load->view($this->session->userdata('foradd'));
	}

	public function edit_form($id){
		$this->load->view($this->session->userdata('foredit'),[
			'edit_data'	=>	$this->asset_main_cat_model->getData($id)
			]);
	}

	public function view_form($id){
		$this->load->view($this->session->userdata('forview'),[
			'edit_data'	=>	$this->asset_main_cat_model->getData($id)
			]);
	}

	public function insert()
	{
		$data = [
			':p_category_code'	=> $this->input->post('catCode'),
			':p_description'	=> $this->input->post('catDesc'),
			':p_enable_flag'	=> ($this->input->post('catEna') == 'ok' ? 'Y' : 'N'),
			':p_user_id'		=> $this->session->userdata('user_id')
		];

		$query = $this->asset_main_cat_model->insert_data($data);
		echo json_encode($query);
	}

	public function update()
	{
		$data = [
			':p_category_code'	=> $this->input->post('catCode_e'),
			':p_description'	=> $this->input->post('catDesc_e'),
			':p_enable_flag'	=> ($this->input->post('catEna_e') == 'ok' ? 'Y' : 'N'),
			':p_user_id'		=> $this->session->userdata('user_id')
		];

		$query = $this->asset_main_cat_model->update_data($data);
		echo json_encode($query);
	}

	public function search(){
		echo json_encode($this->asset_main_cat_model->search($this->input->post('sCode')));
	}
}
